//
//  UserReg.m
//  SenMo
//
//  Created by ZengYuan on 15/12/28.
//  Copyright © 2015年 ZengYuan. All rights reserved.
//

#import "UserReg.h"
#import "Config.h"
#import "HTTP.h"
#import "UserUnit.h"

@implementation UserReg

+(void)userReg:(NSString *)userid andPwd:(NSString *)pwd
       success:(void (^)())success failure:(void (^)(NSString *error))failure{
    
    NSDictionary *dic = [[NSDictionary alloc] initWithObjects: @[userid,pwd] forKeys:@[@"phoneno", @"secret"]];
    
    NSString *json  =[dic JSONString];
    NSString *url = [NSString stringWithFormat:@"http://123.56.73.35:28000/SenMo/%@",URL_REG];
    
    [AWHttpTool post:url body:json success:^(id json) {
        
        NSString* msg = json[@"msg"];
        
        if (json) {
            
            NSInteger sta = [json[@"status"] integerValue];
            
            if (sta == 0) {
                success();
                return ;
            }
        }
        
        failure(msg?msg:HTTPERROR_DATAFAIL);
        
    } failure:^(NSError *error) {
        failure(error.domain);
    }];
    
}

+(void)userSet:(NSString *)phone
                     newpasswd:(NSString *)newpwd
                success:(void (^)())success failure:(void (^)(NSString *error))failure{
    
    NSDictionary *dic = [[NSDictionary alloc]
                         initWithObjects:@[phone,newpwd]
                                 forKeys:@[@"phoneno", @"new_secret"]];
    
    NSString *json  =[dic JSONString];
    NSString *url = [NSString stringWithFormat:@"http://123.56.73.35:28000/SenMo/%@",@"find_secret.action"];
    
    [AWHttpTool post:url body:json success:^(id json) {
        
        NSString *msg = json[@"msg"];
         
        if (json) {
            
            NSInteger sta = [json[@"status"] integerValue];
            
            if (sta == 0) {
                success();
                return ;
            }
        }
        
        failure(msg?msg:HTTPERROR_DATAFAIL);
        
    } failure:^(NSError *error) {
        failure(error.domain);
    }];
    

    
}

@end
